<?php
/**
 * @Notes:【】
 * @Date: 2022-08-08 23:55
 */

namespace App\Service\Ocean;

use App\Dao\Ocean\OceanRankingLogDao;
use App\Dao\Ocean\OceanRankingSettingDao;
use App\Dao\User\UserDao;
use Hyperf\Di\Annotation\Inject;

class OceanRankingService
{
    /**
     * @Inject()
     * @var UserDao
     */
    protected $userDao;

    /**
     * @Inject()
     * @var OceanRankingSettingDao
     */
    protected $oceanRankingSettingDao;
    public function lists(int $user_id=0)
    {
        $res = $this->userDao->select([
            'uid',
            'nickname',
            'avatar',
            'ocean_fish_num',
            'ocean_power',
        ])->orderByDesc('ocean_fish_num')->orderByDesc('ocean_power')
            ->where('ocean_fish_num','>',0)
            ->where('ocean_power','>',0)
            ->limit(100)->get()->map->only([
            'uid',
            'nickname',
            'avatar',
            'ocean_fish_num',
            'ocean_power',
        ]);
        $oc = $this->oceanRankingSettingDao->pluck('reward','rank');
        $res->transform(function ($item,$key) use ($oc){
           $item['reward'] =  $oc->get($key+1,0);
           return $item;
        });
        return $res;
    }

    /**
     * @Inject()
     * @var OceanRankingLogDao
     */
    protected $oceanRankingLogDao;
    public function run(){
        $time = time();

        $datas = $this->lists();

        $datas->where('reward','>',0)->every(function ($data){
            $this->userDao->opAccount('integral', $data['uid'], $data[''], 'exam', 0);
            return true;
        });
    }
}